home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / generic / zip.tex < prev   
Encoding:
Text File  |  1992-08-26  |  2.9 KB  |  89 lines

  1. % zip.tex
  2. % J. Daniel Smith
  3. % 24 May 1990
  4. %
  5. % Modified from a STY file snarfed from someplace else.  But I don't
  6. % remember where the original code came from...  OOPS!!!
  7. %
  8. % Make a barcode for a ZIP code!
  9. %
  10. % Example usage is below.
  11. %
  12. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13. \catcode`@=11    % letter
  14. %
  15. % Dimensions of bars to be used in the barcode
  16. \newdimen\b@rwidth \newdimen\b@rlong \newdimen\b@rshort \newdimen\b@rsep
  17. \b@rwidth=0.02true in \b@rlong=0.125true in \b@rshort=0.05true in
  18. \b@rsep=0.0275true in
  19. \def\sb@r{\vrule height\b@rshort width\b@rwidth depth0pt \kern\b@rsep}
  20. \def\lb@r{\vrule height\b@rlong width\b@rwidth depth0pt \kern\b@rsep}
  21.  
  22. % The barcodes for each digit
  23. \def\zerob@r{\lb@r\lb@r\sb@r\sb@r\sb@r}
  24. \def\oneb@r{\sb@r\sb@r\sb@r\lb@r\lb@r}
  25. \def\twob@r{\sb@r\sb@r\lb@r\sb@r\lb@r}
  26. \def\threeb@r{\sb@r\sb@r\lb@r\lb@r\sb@r}
  27. \def\fourb@r{\sb@r\lb@r\sb@r\sb@r\lb@r}
  28. \def\fiveb@r{\sb@r\lb@r\sb@r\lb@r\sb@r}
  29. \def\sixb@r{\sb@r\lb@r\lb@r\sb@r\sb@r}
  30. \def\sevenb@r{\lb@r\sb@r\sb@r\sb@r\lb@r}
  31. \def\eightb@r{\lb@r\sb@r\sb@r\lb@r\sb@r}
  32. \def\nineb@r{\lb@r\sb@r\lb@r\sb@r\sb@r}
  33.  
  34. \newcount\zipb@rm
  35. \newcount\zipb@rn
  36. \chardef\ten=10
  37.  
  38. %Almost like using \ifcase... except `-' is ignored.
  39. \def\zipb@r@@@#1#2{\expandafter\def\csname zipb@r@@#1\endcsname%
  40.                    {#2\advance\zipb@rn#1\relax}}
  41.  
  42. \newbox\zipbarcode
  43. \zipb@r@@@0{\global\setbox\zipbarcode\hbox{\box\zipbarcode\zerob@r}}
  44. \zipb@r@@@1{\global\setbox\zipbarcode\hbox{\box\zipbarcode\oneb@r}}
  45. \zipb@r@@@2{\global\setbox\zipbarcode\hbox{\box\zipbarcode\twob@r}}
  46. \zipb@r@@@3{\global\setbox\zipbarcode\hbox{\box\zipbarcode\threeb@r}}
  47. \zipb@r@@@4{\global\setbox\zipbarcode\hbox{\box\zipbarcode\fourb@r}}
  48. \zipb@r@@@5{\global\setbox\zipbarcode\hbox{\box\zipbarcode\fiveb@r}}
  49. \zipb@r@@@6{\global\setbox\zipbarcode\hbox{\box\zipbarcode\sixb@r}}
  50. \zipb@r@@@7{\global\setbox\zipbarcode\hbox{\box\zipbarcode\sevenb@r}}
  51. \zipb@r@@@8{\global\setbox\zipbarcode\hbox{\box\zipbarcode\eightb@r}}
  52. \zipb@r@@@9{\global\setbox\zipbarcode\hbox{\box\zipbarcode\nineb@r}}
  53.  
  54. \def\zipb@r@@#1{\csname zipb@r@@#1\endcsname}
  55.  
  56. \def\zipb@r@#1{\ifx#1\null
  57.                  \let\next\relax
  58.             \else
  59.            \zipb@r@@{#1}#1%
  60.                 \let\next\zipb@r@
  61.             \fi
  62.             \next}
  63.  
  64. \def\zipbar#1{\setbox\zipbarcode=\null
  65.  \hbox{ % put numbers in an \hbox
  66.    \global\setbox\zipbarcode\hbox{\box\zipbarcode\lb@r} % start with long bar
  67.    \zipb@rn\z@\zipb@r@#1\null
  68.    \zipb@rm\zipb@rn \divide\zipb@rm\ten \multiply\zipb@rm\ten
  69.    \advance\zipb@rm-\zipb@rn
  70.    \ifnum\zipb@rm<0
  71.     \advance\zipb@rm\ten
  72.    \fi
  73.    \zipb@r@@{\the\zipb@rm} % last digit, so that the sum is divisible by ten
  74.    \global\setbox\zipbarcode\hbox{\box\zipbarcode\lb@r}% end with a long bar
  75.    } % end of \hbox
  76. }
  77.  
  78. \catcode`@=12  % disable private sequences
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %
  81. %\zipbar{1234567890}
  82. %
  83. %\zipbar{48837}
  84. %
  85. %\zipbar{78653--0102}
  86. %\bye
  87. \endinput
  88.